#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define sz(x) (ll)x.size()
#define rep(i,x,y) for(ll i=(x);i<=(y);i++)
using namespace std;
using ll=long long;
using pll=pair<ll,ll>;
const ll N=500005;
const ll inf=0x3f3f3f3f3f3f3f3f;
ll n,c,b[N];
vector<ll> day[N];
int main(){
	ios::sync_with_stdio(0),cin.tie(0);
	freopen("list.in","r",stdin);
	freopen("list.out","w",stdout);
	cin>>n;
	vector<ll> gap;
	vector<pll> gap2;
	unordered_map<ll,ll> cnt;
	ll sumgap=0;
	rep(i,1,n){
		ll x;
		cin>>x;
		sumgap+=x;
		rep(j,1,x){
			ll y;
			cin>>y;
			cnt[y]++;
			if(!day[i].empty()){
				ll gp=y-day[i].back();
				gap.pb(gp);
				gap2.pb({gp,y});
			}
			day[i].pb(y);
		}
	}
	sort(gap.begin(),gap.end());
	sort(gap2.begin(),gap2.end());
	gap.erase(unique(gap.begin(),gap.end()),gap.end());
	cin>>c;
	rep(i,1,n){
		cin>>b[i];
	}
	ll sum=sumgap*c;
	for(pll i:cnt){
		sum+=i.se*b[i.se];
	}
	ll ans=sum,lst=1,ssz=0;
	vector<ll> ans2;
	ans2.pb(1);
	for(ll i:gap){
		auto l=lower_bound(gap2.begin(),gap2.end(),(pll){i,0});
		auto r=lower_bound(gap2.begin(),gap2.end(),(pll){i,inf});
		vector<ll> infl;
		for(auto i=l;i!=r;i++){
			infl.pb(i->se);
		}
		ssz+=sz(infl);
		sum+=(sz(infl)*(i-lst)+(sumgap-ssz)*(i+1-lst))*c;
		ll lst2=0;
		for(ll j:infl){
			if(j>lst2){
				sum-=cnt[j]*b[cnt[j]];
				lst2=j;
			}
		}
		for(ll j:infl){
			cnt[j]--;
		}
		lst2=0;
		for(ll j:infl){
			if(j>lst2){
				sum+=cnt[j]*b[cnt[j]];
				lst2=j;
			}
		}
		if(sum==ans){
			ans2.pb(i+1);
		}
		else if(sum<ans){
			ans=sum;
			ans2.clear();
			ans2.pb(i+1);
		}
		lst=i+1;
	}
	cout<<ans<<' '<<sz(ans2)<<'\n';
	for(ll i:ans2){
		cout<<i<<' ';
	}
	return 0;
}
